package com.finance.system.service;

import com.finance.framework.lang.Page;
import com.finance.framework.lang.PageResultBO;
import com.finance.rule.bean.pojo.MajorRule;
import com.finance.system.bean.pojo.Supplier;
import com.finance.system.bean.pojo.SupplierGroup;
import com.finance.system.dao.SupplierMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by gly on 2017/4/1.
 */
@Service
public class SupplierService implements ISupplierService {

    @Resource
    private SupplierMapper supplierMapper;

    @Override
    public PageResultBO<Supplier> listByPage(Page page) {
        PageResultBO<Supplier> pageResultBO = new PageResultBO<Supplier>();
        List<Supplier> list = supplierMapper.listByPage(page);
        pageResultBO.setPageSize(page.getPageSize());
        pageResultBO.setTotalRecord(page.getTotalRecord());
        pageResultBO.setPageNo(page.getPageNo());
        pageResultBO.setDataList(list);
        return pageResultBO;
    }

    @Override
    public Supplier getById(Long id) {
        return supplierMapper.getById(id);
    }

    @Override
    public Supplier getByCode(String code) {
        return supplierMapper.getByCode(code);
    }

    @Override
    public Boolean add(Supplier supplier) {
        return supplierMapper.add(supplier) == 1;
    }

    @Override
    public Boolean delete(Long uid, List<String> ids) {
        return supplierMapper.delete(uid, ids) > 0;
    }

    @Override
    public Boolean update(Supplier supplier) {
        return supplierMapper.update(supplier) == 1;
    }

    @Override
    public List<Supplier> listAll() {
        return supplierMapper.listAll();
    }

    @Override
    public List<Map<String, String>> listGroups() {
        return supplierMapper.listGroups();
    }

    @Override
    public String getGroupIdByName(String name) {
        return supplierMapper.getGroupIdByName(name);
    }

    @Override
    public MajorRule getRuleByName(String name) {
        return supplierMapper.getRuleByName(name);
    }



    @Override
    public Long addGroup(SupplierGroup supplierGroup) {
        supplierMapper.addGroup(supplierGroup);
        return supplierGroup.getId();
    }

    @Override
    public Boolean codeIsExist(String code) {
        return supplierMapper.codeIsExist(code)==0;
    }

    @Override
    public Boolean groupCodeIsExist(String code) {
        return supplierMapper.groupCodeIsExist(code)==0;
    }

    @Override
    public Long addRule(MajorRule majorRule) {
        supplierMapper.addRule(majorRule);
        return majorRule.getId();
    }

    @Override
    public MajorRule getRuleById(String id) {
        return supplierMapper.getRuleById(id);
    }

    @Override
    public Boolean updateRule(MajorRule majorRule) {
        return supplierMapper.updateRule(majorRule)==1;
    }

    @Override
    public String getCodeByName(String name) {
        return supplierMapper.getCodeByName(name);
    }


}
